package dsk.demo.product.config;

import com.baomidou.mybatisplus.extension.plugins.pagination.DialectModel;
import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect;

/**
 * 自定义SQL解析器  在指定位置 插入 LIMIT
 */
public class MyDialect implements IDialect{
    public MyDialect() {
    }

    public DialectModel buildPaginationSql(String originalSql, long offset, long limit) {
        String sql="";
        if(originalSql.indexOf("/*LIMIT*/")>=0){
            sql = originalSql.replace("/*LIMIT*/"," LIMIT " + "?" + "," + "?");
        }else{
            sql = originalSql + " LIMIT " + "?" + "," + "?";
        }
        return (new DialectModel(sql, offset, limit)).setConsumerChain();
    }
}
